# -*- coding: utf-8 -*-
# @时间：2023/11/7 14:40
# @作者：CJiaの可乐哥
# @文件名：error_log
# @软件：Pycharm2023
from typing import List

from ninja import Router, Schema, Field, Query, ModelSchema
from ninja.pagination import paginate
from system.models import ErrorLog

from utils.cj_curd import retrieve
from utils.cj_ninja import MyPagination

router = Router()


class Filters(Schema):
    id: str = Field(None, alias="error_log_id")
    request_username: str = Field(None, alias="request_username")


class SchemaOut(ModelSchema):
    class Config:
        model = ErrorLog
        model_fields = "__all__"


@router.get("/error_log", response=List[SchemaOut])
@paginate(MyPagination)
def list_error_log(request, filters: Filters = Query(...)):
    qs = retrieve(request, ErrorLog, filters)
    return qs.order_by("-id")
